package teamGiga.action;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import teamGiga.bean.MovieBean;
import teamGiga.dao.MovieDao;
import action.servlet.ActionForWard;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;

public class InsertmvifAction extends Action{
	private String path;
	private boolean redirect;

	public InsertmvifAction() {
		super();
	}
	public InsertmvifAction(String path, boolean redirect) {
		super();
		this.path = path;
		this.redirect = redirect;
	}
	
	@Override
	public ActionForWard execute(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			MultipartRequest mr= new MultipartRequest
					(request, "C:\\workspace\\teamGiga\\teamGiga\\WebContent\\upload\\", 1024*1024*1024, "euc-kr",new DefaultFileRenamePolicy());
			MovieBean mBean=new MovieBean();
			mBean.setMname(mr.getParameter("mname"));
			mBean.setGenre(mr.getParameter("genre"));
			mBean.setDirector(mr.getParameter("director"));
			mBean.setActor(mr.getParameter("actor"));
			mBean.setRdate(mr.getParameter("rdate"));
			mBean.setRuntime(Integer.parseInt(mr.getParameter("runtime")));
			mBean.setGrade(Integer.parseInt(mr.getParameter("grade")));
			mBean.setSyn(mr.getParameter("syn"));
			if(mr.getFilesystemName("imgname")!=null){
			mBean.setImgName(mr.getFilesystemName("imgname"));
			}
			if(mr.getFilesystemName("vodname")!=null){
			mBean.setVodName(mr.getFilesystemName("vodname"));
			}
			MovieDao.insertMovie(mBean);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return new ActionForWard(path, redirect);
	}
}
